package {tmpl_var name='package'} {
	import mx.collections.ArrayCollection;
	import org.davekeen.flextrine.orm.FlextrineError;
	
	[Bindable]
	public class {tmpl_var name='classname'}EntityBase {
		
		public var __isUnserialized__:Boolean;
		
		public var __isInitialized__:Boolean = true;
		
		public var __isCollectionInitializedMap__:Object = new Object();
		
<tmpl_loop name='fieldsloop'>
<tmpl_if name='id'>		[Id]
		public var {tmpl_var name='name'}:{tmpl_var name='type'};
		
<tmpl_else>		public function get {tmpl_var name='name'}():{tmpl_var name='type'} { checkIsInitialized("{tmpl_var name='name'}"); return <tmpl_if name='type' op='==' value='Date'>(_{tmpl_var name='name'} && _{tmpl_var name='name'}.getTime() > 0) ? _{tmpl_var name='name'} : null<tmpl_else>_{tmpl_var name='name'}</tmpl_if>; }
		public function set {tmpl_var name='name'}(value:<tmpl_if name='type' op='==' value='Date'>*<tmpl_else>{tmpl_var name='type'}</tmpl_if>):void { _{tmpl_var name='name'} = <tmpl_if name='type' op='==' value='Date'>(value is Date) ? value : new Date(value)<tmpl_else>value</tmpl_if>; }
		private var _{tmpl_var name='name'}:{tmpl_var name='type'}<tmpl_if name='type' op='==' value='Number'> = 0</tmpl_if>;
		
</tmpl_if>
</tmpl_loop>
<tmpl_loop name='associationsloop'>
		[Association]
		public function get {tmpl_var name='name'}():{tmpl_var name='type'} { checkIsInitialized("{tmpl_var name='name'}"); return _{tmpl_var name='name'}; }
		public function set {tmpl_var name='name'}(value:{tmpl_var name='type'}):void { _{tmpl_var name='name'} = value; }
		private var _{tmpl_var name='name'}:{tmpl_var name='type'};
		
</tmpl_loop>
		public function {tmpl_var name='classname'}EntityBase() {
<tmpl_loop name='associationsloop'>
<tmpl_if name='type' op='==' value='ArrayCollection'>			{tmpl_var name='name'} = new ArrayCollection();
</tmpl_if>
</tmpl_loop>
		}
		
		public function toString():String {
			return "[{tmpl_var name='classname'} <tmpl_loop name='identifiersloop'>{tmpl_var name='identifier'}=" + {tmpl_var name='identifier'} + "</tmpl_loop>]";
		}
		
		private function checkIsInitialized(property:String):void {
			if (!__isInitialized__ && __isUnserialized__)
				throw new FlextrineError("Attempt to get property '" + property + "' on unitialized {tmpl_var name='classname'}.  Consider using EntityManager::require or eager loading.", FlextrineError.ACCESSED_UNITIALIZED_ENTITY);
		}
		
	}

}
